package com.yundian.cloudme.action;



import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.yundian.member.service.impl.MemberService;
import com.yundian.shop.service.impl.ShopService;
import com.yundian.user.service.impl.UserService;
import com.yundian.vo.Member;
import com.yundian.vo.Shop;

public class CloudMeLoginRegisterAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	String result;
	UserService userService; 
	MemberService memberService;
	ShopService shopService;
	String UName;
	String UPassword;
	String UEmail;
	Member member;
	Shop shop;
	
	Integer URole;
	String ActionMsg=null;
	
   public String register() throws Exception{
	   if(UName.length()>0&&UEmail.length()>0&&UPassword.length()>0){
		   if(memberService.getMemberByMemberEmail(UEmail)==null){
			member= memberService.registerMember(UName, UEmail, UPassword);
			ServletActionContext.getRequest().getSession().setAttribute("member", member);
			return "success";
		   }
	   }else
		   ActionMsg="用户已经存在！";
	   return "register";
	}
   public String login() throws Exception{
	   System.out.println(UEmail+URole);
	   if(URole==1){
		   member=memberService.validateMember(UEmail,UPassword);
		   if(member!=null){
			 ServletActionContext.getRequest().getSession().setAttribute("member", member);
			 return "memberSuccess";
		   }else
			   ActionMsg="error!";
	   }else if(URole==2){
		   shop=shopService.loginShop(UEmail, UPassword);
		   if(shop!=null){
			   ServletActionContext.getRequest().getSession().setAttribute("shop", shop);
			   return "shopSuccess";
		   }else
			 ActionMsg="error!";
	   }
		return "login";
	}
   public String logout() throws Exception{
	   
		return "success";
	}
	public String getResult() {
		return result;
	}
	public ShopService getShopService() {
		return shopService;
	}
	public void setShopService(ShopService shopService) {
		this.shopService = shopService;
	}
	public Shop getShop() {
		return shop;
	}
	public void setShop(Shop shop) {
		this.shop = shop;
	}
	public Integer getURole() {
		return URole;
	}
	public void setURole(Integer role) {
		URole = role;
	}
	public String getActionMsg() {
		return ActionMsg;
	}
	public void setActionMsg(String actionMsg) {
		ActionMsg = actionMsg;
	}
	public MemberService getMemberService() {
		return memberService;
	}
	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}
	public Member getMember() {
		return member;
	}
	public void setMember(Member member) {
		this.member = member;
	}
	public String getUName() {
		return UName;
	}
	public void setUName(String name) {
		UName = name;
	}
	public String getUPassword() {
		return UPassword;
	}
	public void setUPassword(String password) {
		UPassword = password;
	}
	public String getUEmail() {
		return UEmail;
	}
	public void setUEmail(String email) {
		UEmail = email;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public static long getSerialVersionUID() {
		return serialVersionUID;
	}
	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	
}
